// 通过找出
// let n = parseInt(readline());
// const arr1 = readline().split(' ').map(Number);
// const arr2 = [];
// if (n === 1) {
//     console.log(arr1[0]);
// } else {
//     for (let i = 0; i < n - 1; i++) {
//         arr2.push(arr1[i] * arr1[i + 1]);
//     }
//     let maxtemp = Math.max(...arr2);
//     let index = arr2.indexOf(maxtemp);
//     let count = 0;
//     for (let i = 0; i < n; i++) {
//         if (i === index) {
//             count += Math.max(maxtemp, arr1[i] + arr1[i + 1]);
//             i++;
//         } else {
//             count += arr1[i];
//         }
//     }
//     console.log(count);
// }

let n = parseInt(readline());
const arr1 = readline().split(' ').map(Number);
let oldsum = 0;
let newsum = 0;
let sum = 0;
if (n === 1) {
    console.log(arr1[0]);
}
else {
    for (let i = 0; i < n; i++) {
        oldsum += arr1[i];
    }
    for (let i = 0; i < n - 1; i++) {
        newsum = oldsum - arr1[i] - arr1[i + 1] + (arr1[i] * arr1[i + 1]);
        sum = Math.max(sum, newsum);
    }
    console.log(sum)
}
/*
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        long[] a=new long[n];
        long oldsum=0;
        long newsum=0;
        for(int i=0;i<n;i++){
            a[i]=in.nextInt();
            oldsum+=a[i];
        }
        if(n==1){
            System.out.println(oldsum);
        }else{
            long maxsum=oldsum;
            for(int i=0;i<n-1;i++){
                newsum=oldsum+(1L*a[i]*a[i+1])-(a[i]+a[i+1]);
                if(maxsum < newsum){
                    maxsum=newsum;
                }
            }
            System.out.println(maxsum);
        }
            
        in.close();
    }

}

*/
